<?php
require_once APPPATH."models/model_dao.php";
class Model_data extends Model_dao {
	var $_tbl_name;

	function Model_data() {
		// Call the Model constructor
		parent :: Model_dao('tbl_data');
	}

	function find($id)
	{
		$this->db->select('*');
		$this->db->where('id', $id);
		$query = $this->db->get($this->_tbl_name);

		if ($query->num_rows() > 0) {
			$data = $query->first_row('array');
			return $data;
		}
		return null;
	}

	function find_by_group($gid, $limit = 10, $offset = 0, $order_by = 'sort', $method = "ASC"){
		$this->db->select('*');
		$this->db->where('gid', $gid);
		$this->db->order_by($order_by, $method);
		$this->db->limit($limit, $offset);
		$query = $this->db->get($this->_tbl_name);
		//echo $this->db->last_query();
		if ($query->num_rows() > 0) {
			$data = $query->result_array();
			return $data;
		}
		return null;
	}

	/**
	 *
	 *
	 */
	function find_by_group_count($gid){
		$this->db->where('gid', $gid);
		$this->db->from($this->_tbl_name);
		return $this->db->count_all_results();
	}
}
?>